package com.test.mooan.labama.dialog_boom;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.test.mooan.labama.R;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;

public class PhotoChooseDialog_boom extends Dialog{

    private final String pageTag;

    private final Runnable cameraRunnable;
    private final Runnable albumRunnable;

    public PhotoChooseDialog_boom(@NonNull Context context, Runnable cameraRunnable, Runnable albumRunnable){
        super(context);
        this.pageTag = "PHOTO_CHOOSE";
        this.cameraRunnable = cameraRunnable;
        this.albumRunnable = albumRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_photo_choose_boom);
        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        setCanceledOnTouchOutside(false);
        init();
    }

    @SuppressLint("SetTextI18n")
    private void init(){

        findViewById(R.id.dialog_photo_choose_iv_close).setOnClickListener(v -> dismiss());

        findViewById(R.id.dialog_photo_choose_btn_camera).setOnClickListener(v -> {
            UserInfoHelper_boom.gInstance().addEventPoint((pageTag + "_TAKE_A_PHOTO_CLICK").toUpperCase());
            if (cameraRunnable!=null) cameraRunnable.run();
            dismiss();
        });

        findViewById(R.id.dialog_photo_choose_btn_album).setOnClickListener(v -> {
            UserInfoHelper_boom.gInstance().addEventPoint((pageTag + "_UPLOAD_FROM_ALBUM_CLICK").toUpperCase());
            if (albumRunnable!=null) albumRunnable.run();
            dismiss();
        });

    }

    @Override
    public void show() {
        super.show();
        UserInfoHelper_boom.gInstance().addEventPoint(pageTag +"_START");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        UserInfoHelper_boom.gInstance().addEventPoint(pageTag +"_END");
    }

}
